import './App.scss';
import { HashRouter, Routes, Route } from 'react-router-dom';
import { routes, Guard } from './router/index' 

function RouteAuthFun(routeList) {
  return (
    routeList.map((item)=>{
      return (
        <Route key={item.path} path={item.path} element={
          <Guard auth={item.auth}>{item.element}</Guard>
        }>
          {/* 递归调用，因为可能存在多级的路由 */}
          {item?.children && RouteAuthFun(item.children)}
        </Route>
      )
    })
  )
}

function App() {
  return (
    <HashRouter>
      <Routes>
        {RouteAuthFun(routes)}
      </Routes>
    </HashRouter>
  );
}

export default App;
